package org.iabako.server.dao.report;

import org.iabako.server.dao.business.FinanceDAO;
import org.iabako.shared.dto.FinancesBalance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by jose on 28/01/15.
 */

@Repository("profitReportDAO")
public class ProfitReportDAO extends AbstractReportDAO {

    @Autowired
    FinanceDAO financeDAO;

    public Map<Object, FinancesBalance> getProfitBy(Date dateAfter, Date dateBefore) {

        Map<Object, FinancesBalance> profitsBy = new HashMap<Object, FinancesBalance>();

        FinancesBalance fb = financeDAO.getFinancesBalance(dateAfter, dateBefore, false);
        FinancesBalance financeBalanceSales = new FinancesBalance(fb.getSalesPayed(), fb.getSalesReceivable(), null, null);
        FinancesBalance financeBalanceExpenses = new FinancesBalance(null, null, fb.getExpensesPayed(), fb.getExpensesPayable());

        profitsBy.put(messages.getLabel("sales"), financeBalanceSales);
        profitsBy.put(messages.getLabel("expenses"), financeBalanceExpenses);

        return profitsBy;
    }
}
